﻿using System;
using System.Collections.Generic;

namespace BSharp.Compiler.Emit
{
	public class FunctionBuilder : IFunctionInfo
	{
		private string name;
		private int placementNew = 0;

		public string Name {
			get {
				return name;
			}
		}

		public int LocalSize {
			get {
				return placementNew;
			}
		}

		private List<IntermediateInstruction> instructions = new List<IntermediateInstruction> ();

		public FunctionBuilder (string name)
		{
			this.name = name;
		}

		public int StackAlloc (int amount)
		{
			placementNew += amount;
			return placementNew - amount;
		}

		public void Emit (IntermediateInstruction instruction)
		{
			instructions.Add (instruction);
		}

		public IEnumerable<IntermediateInstruction> GetInstructions ()
		{
			return instructions;
		}
	}
}

